﻿using Economo.Services.MessageContracts;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF;
using Economo.Services.BusinessLogic;


namespace Economo.Services.ServiceImplementation
{
    [ExceptionShielding(ExceptionHandling.ManageExceptions.ServicesPolicy)]
    public class AccountsService : IAccountsService
    {
        #region Banks
        public GetBanksByDescriptionResponse GetBanksByDescription(GetBanksByDescriptionRequest request)
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            GetBanksByDescriptionResponse response = new GetBanksByDescriptionResponse();            
            
            response.Banks =  bl.GetBanksByDescription(request.Description);
            return response;
            //return null;
        }

        public void UpdateBank(UpdateBankRequest request)
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            bl.UpdateBank(request.Bank);
        }

        public void DeleteBankById(DeleteBankByIdRequest request)
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            bl.DeleteBank(request.BankId);
        }

        public void DeleteBank(DeleteBankRequest request)
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            bl.DeleteBank(request.Bank);
        }

        public InsertBankResponse InsertBank(InsertBankRequest request)
        {
            BanksBusinessLogic bl = new BanksBusinessLogic();
            InsertBankResponse response = new InsertBankResponse();
            response.BankId = bl.InsertBank(request.Bank);
            return response;
        }
        #endregion
        #region BankAccounts
        public GetBanksAccountsResponse GetAllBanksAccounts()
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            GetBanksAccountsResponse response = new GetBanksAccountsResponse();
            response.Accounts = bl.GetBankAccounts();
            return response;
        }
        public GetBanksAccountsResponse GetBankAccounts(GetBankAccountsRequest request)
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            GetBanksAccountsResponse response = new GetBanksAccountsResponse();
            response.Accounts = bl.GetBankAccounts(request.BankId);
            return response;
        }
        public void UpdateBankAccount(UpdateBankAccountRequest request)
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            bl.UpdateAccount(request.Account);
        }

        public void DeleteBankAccountById(DeleteBankAccountByIdRequest request)
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            bl.DeleteAccount(request.BankId,request.AccountId);
        }

        public void DeleteBankAccount(DeleteBankAccountRequest request)
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            bl.DeleteAccount(request.Account);
        }

        public InsertBankAccountResponse InsertBankAccount(InsertBankAccountRequest request)
        {
            BankAccountsBusinessLogic bl = new BankAccountsBusinessLogic();
            InsertBankAccountResponse response = new InsertBankAccountResponse();
            response.AccountId  = bl.InsertAccount(request.Account);
            return response;
        }
        #endregion
        #region CreditCards
        public GetCreditCardsResponse GetAllCreditCards()
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            GetCreditCardsResponse response = new GetCreditCardsResponse();
            response.Cards = bl.GetCreditCards();
            return response;
        }
        public GetCreditCardsResponse GetBankCreditCards(GetCreditCardsRequest request)
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            GetCreditCardsResponse response = new GetCreditCardsResponse();
            response.Cards = bl.GetCreditCards(request.BankId);
            return response;
        }
        public void UpdateCreditCard(UpdateCreditCardRequest request)
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            bl.Update(request.Card);
        }

        public void DeleteCreditCardById(DeleteCreditCardByIdRequest request)
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            bl.Delete(request.BankId, request.CardId);
        }

        public void DeleteCreditCard(DeleteCreditCardRequest request)
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            bl.Delete(request.Card);
        }

        public InsertCreditCardResponse InsertCreditCard(InsertCreditCardRequest request)
        {
            CreditCardsBusinessLogic bl = new CreditCardsBusinessLogic();
            InsertCreditCardResponse response = new InsertCreditCardResponse();
            response.CardId = bl.Insert(request.Card);
            return response;
        }
        #endregion

        #region AccountTypes
        public GetAccountTypeByIdResponse GetAccountTypeById(GetAccountTypeByIdRequest request)
        {
            AccountTypesBusinessLogic bl = new AccountTypesBusinessLogic();
            GetAccountTypeByIdResponse response = new GetAccountTypeByIdResponse();

            response.AccountType = bl.GetAccountTypeById(request.Id);
            return response;
            //return null;
        }

        public void UpdateAccountType(UpdateAccountTypeRequest request)
        {
            AccountTypesBusinessLogic bl = new AccountTypesBusinessLogic();
            bl.UpdateAccountType(request.AccountType);
        }

        public void DeleteAccountTypeById(DeleteAccountTypeByIdRequest request)
        {
            AccountTypesBusinessLogic bl = new AccountTypesBusinessLogic();
            bl.DeleteAccountType(request.AccountTypeId);
        }

        public InsertAccountTypeResponse InsertAccountType(InsertAccountTypeRequest request)
        {
            AccountTypesBusinessLogic bl = new AccountTypesBusinessLogic();
            InsertAccountTypeResponse response = new InsertAccountTypeResponse();
            response.AccountTypeId = bl.InsertAccountType(request.AccountType);
            return response;
        }
        #endregion

        #region Accounts
        public GetAccountByIdResponse GetAccountById(GetAccountByIdRequest request)
        {
            AccountsBusinessLogic bl = new AccountsBusinessLogic();
            GetAccountByIdResponse response = new GetAccountByIdResponse();

            response.Account = bl.GetAccountById(request.Id);
            return response;
            //return null;
        }

        public void UpdateAccount(UpdateAccountRequest request)
        {
            AccountsBusinessLogic bl = new AccountsBusinessLogic();
            bl.UpdateAccount(request.Account);
        }

        public void DeleteAccountById(DeleteAccountByIdRequest request)
        {
            AccountsBusinessLogic bl = new AccountsBusinessLogic();
            bl.DeleteAccount(request.AccountId);
        }

        public InsertAccountResponse InsertAccount(InsertAccountRequest request)
        {
            AccountsBusinessLogic bl = new AccountsBusinessLogic();
            InsertAccountResponse response = new InsertAccountResponse();
            response.AccountId = bl.InsertAccount(request.Account);
            return response;
        }
        #endregion
    }
}
